package cn.dansj.common.utils.json;

import cn.dansj.common.utils.transfer.DateTime;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.util.Date;

class DateDeserializer extends JsonDeserializer<Date> {
    public static final DateDeserializer INSTANCE = new DateDeserializer();

    @Override
    public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String dateStr = p.getText();
        try {
            return DateTime.getInstance(dateStr).toDate();
        } catch (Throwable e) {
            return ctxt.parseDate(dateStr);
        }
    }
}